package com.ningxia.water.reuslt;

import com.ningxia.water.exception.BaseErrorInfoInterface;

/**
 * 响应结果生成工具
 * @author hz
 * @since 2021-03-15
 */
public class ResultResponse {

    /**
     * 成功
     *
     * @return
     */
    public static Result getSuccessResult() {
        return getSuccessResult(null);
    }

    /**
     * 成功
     * @param data
     * @return
     */
    public static Result getSuccessResult(Object data) {
        Result rb = new Result();
        rb.setCode(ResultCode.SUCCESS.getResultCode());
        rb.setMessage(ResultCode.SUCCESS.getResultMsg());
        rb.setData(data);
        return rb;
    }

    /**
     * 失败
     */
    public static Result getFailResult(BaseErrorInfoInterface errorInfo) {
        Result rb = new Result();
        rb.setCode(errorInfo.getResultCode());
        rb.setMessage(errorInfo.getResultMsg());
        rb.setData(null);
        return rb;
    }

    /**
     * 失败,携带状态码
     */
    public static Result getFailResult(String code, String message) {
        Result rb = new Result();
        rb.setCode(code);
        rb.setMessage(message);
        rb.setData(null);
        return rb;
    }

    /**
     * 失败
     */
    public static Result getFailResult( String message) {
        Result rb = new Result();
        rb.setCode("-1");
        rb.setMessage(message);
        rb.setData(null);
        return rb;
    }
}

